package com.tdxy.pm;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MyPanel extends JPanel {
    JFrame frame ;
    JButton jButton ;
    public MyPanel( JFrame frame) {
        jButton = new JButton();
        this.frame = frame ;
        jButton.setBounds(10,10,100,40);
        jButton.setText("返回");
        this.add(jButton);
        jButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                CardLayout layout = (CardLayout) frame.getContentPane().getLayout() ;
                layout.show(frame.getContentPane(),"indexPanel");
            }
        });
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        g.setColor(Color.MAGENTA);
        g.fillRect(0,0,800,600);
        jButton.repaint();
    }
}
